/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var addTwoNumbers = function(l1, l2) {
  if (!l1 && !l2) {
    return;
  }
  l1 = l1 || new ListNode();
  l2 = l2 || new ListNode();
  const sum = l1.val + l2.val;
  const sumTen = parseInt((sum % 100) / 10)
  if (sumTen) {
    if (l1.next) l1.next.val += sumTen
    else l1.next = new ListNode(sumTen)
  }
  const next = addTwoNumbers(l1.next, l2.next);
  return new ListNode(parseInt(sum % 10), next);
};
